layui.use('element', function(){
    var $ = layui.jquery
        ,element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
    //触发事件
    var active = {
        tabChange: function(){
            //切换到指定Tab项
            element.tabChange('demo', '22');
        }
    };
});

var vm = new Vue({
    el : "#buyStorage",
    data : {
        xtlist:[],
        jblist:[],
        ydmlist:[],
        cmlist:[]
    },
    init:function(){
        var _self = this;
        this.$nextTick(function() {
            this.$http.post(host +"buystorage/selectAllList","",{emulateJSON: true}).then(function(res){
                if(res.ok){
                    _self.xtlist = res.body.XuantouList;
                    _self.jblist = res.body.ProductJbList;
                    _self.ydmlist = res.body.ProductYdmList;
                    _self.cmlist = res.body.SizeList;
                }
                layui.use(['form'], function(){
                    var form = layui.form;

                    form.on('select(xtId)', function(data){
                        _self.xtids = data.value;
                        $.ajax({
                            url: host + "buystorage/selectProductXtList",
                            type: 'POST',
                            async: false,
                            data: {
                                xtids:_self.xtids
                            },
                            dataType: 'json',
                            success: function(data) {
                                if(data.result){
                                    var  xxLists = data.xxList;

                                    var optionstring = "";

                                    for(var i = 0 ; i < xxLists.length ; i++){
                                        optionstring += "<option value=\"" + xxLists[i].WLID + "\" >" + xxLists[i].XXTYPE + "</option>";
                                    };
                                    $("#productId").html('<option value=""></option>' + optionstring);
                                    form.render('select'); //这个很重要


                                }else{
                                    layer.msg("处理失败");
                                }
                            }
                        });
                    });

                });
            });
        });

    },
    methods: {
        saveXuanTouLists: function(data){
            /*获取楦型及物料ID*/
            var productList = document.getElementById("productId");   //物料ID

            var values = productList.options;
            var nums = productList.selectedIndex;

            //获取value值
            var productId = productList.value;
            //获取文本值
            var productCode = values[nums].text;

            /*获取尺码ID及尺码*/
            var sizeList = document.getElementById("sizeId");

            //如何获得该下拉框所有的option的节点对象
            var options = sizeList.options;
            //如何获得当前选中的option的索引？
            var index = sizeList.selectedIndex;

            //获取value值
            var sizeId = sizeList.value;
            //获取文本值
            var sizeCode = options[index].text;


            //获取RFID号
            /*var RFID = document.getElementById("XTRFID").value;*/

            var RFID = "";

            var chestr =$("input[name='Foot']:checked").val(); //获取左右脚的值

            var data ={
                productId:productId,
                productCode:productCode,
                sizeId:sizeId,
                sizeCode:sizeCode,
                chestr:chestr,
                RFID:RFID
            };

            this.$nextTick(function() {
                this.$http.post(host +"buystorage/saveProduct",data,{emulateJSON: true}).then(function(res){
                    if(res.ok){
                        layer.msg("入库成功！");
                        var rfidcode = res.body.rfidcode;
                        top.layer.open({
                            type: 2,
                            title: "写入RFID",
                            shadeClose: true,
                            shade: 0.6,
                            area: ['300', '120'],
                            fixed:true,
                            content: 'http://localhost:28088/xdRfid/write?rfid=' + rfidcode,
                            end:function(){
                            }
                        });
                        window.setTimeout(function() {
                            window.location.reload();
                        }, 1000);
                    }else{
                        layer.msg("入库失败");
                    }
                });
            });
        },
        saveJbLists: function(data){
            /*获取夹板物料ID*/
            var productList = document.getElementById("jbId");   //物料ID
            //获取value值
            var productId = productList.value;

            var productCode = "";

            /*获取尺码ID及尺码*/
            var sizeList = document.getElementById("jbsizeId");

            //获取value值
            var sizeId = sizeList.value;
            //获取文本值
            var sizeCode = "";

            var chestr =$("input[name='Foot']:checked").val(); //获取左右脚的值


            //获取夹板RFID号
            var RFID = document.getElementById("JBRFID").value;

            var data ={
                productId:productId,
                productCode:productCode,
                sizeId:sizeId,
                sizeCode:sizeCode,
                chestr:chestr,
                RFID:RFID
            };

            this.$nextTick(function() {
                this.$http.post(host +"buystorage/saveProduct",data,{emulateJSON: true}).then(function(res){
                    if(res.ok){
                        layer.msg("入库成功！");
                        var rfidcode = res.body.rfidcode;
                        top.layer.open({
                            type: 2,
                            title: "写入RFID",
                            shadeClose: true,
                            shade: 0.6,
                            area: ['300', '120'],
                            fixed:true,
                            content: 'http://localhost:28088/xdRfid/write?rfid=' + rfidcode,
                            end:function(){
                            }
                        });
                        window.setTimeout(function() {
                            window.location.reload();
                        }, 1000);
                    }else{
                        layer.msg("入库失败");
                    }
                });
            });
        },
        saveYdmLists: function(data){
            /*获取压底膜物料ID*/
            var productList = document.getElementById("ydmId");   //物料ID
            //获取value值
            var productId = productList.value;

            var productCode = "";

            /*获取尺码ID及尺码*/
            var sizeList = document.getElementById("ydmsizeId");

            //如何获得该下拉框所有的option的节点对象
            var options = sizeList.options;
            //如何获得当前选中的option的索引？
            var index = sizeList.selectedIndex;

            //获取value值
            var sizeId = sizeList.value;
            //获取文本值
            var sizeCode = options[index].text;

            //获取RFID号
            /*var RFID = document.getElementById("YDMRFID").value;;*/
            var RFID = "";

            var chestr =$("input[name='Foot']:checked").val(); //获取左右脚的值

            var data ={
                productId:productId,
                productCode:productCode,
                sizeId:sizeId,
                sizeCode:sizeCode,
                chestr:chestr,
                RFID:RFID
            };

            this.$nextTick(function() {
                this.$http.post(host +"buystorage/saveProduct",data,{emulateJSON: true}).then(function(res){
                    if(res.ok){
                        layer.msg("入库成功！");
                        var rfidcode = res.body.rfidcode;
                        top.layer.open({
                            type: 2,
                            title: "写入RFID",
                            shadeClose: true,
                            shade: 0.6,
                            area: ['300', '120'],
                            fixed:true,
                            btn:[
                                {

                                }
                            ],
                            content: 'http://localhost:28088/xdRfid/write?rfid=' + rfidcode,
                            end:function(){

                            }
                        });
                        window.setTimeout(function() {
                            window.location.reload();
                        }, 1000);
                    }else{
                        layer.msg("入库失败");
                    }
                });
            });
        },
        reset:function(){
            window.location.reload();
        }
        ,vueAlert:function(msg){
            layui.use(['form'], function(){
                var layer = layui.layer;
                layer.msg(msg,{icon:6,time:2000});
            });
        }
        ,clearReceiveForm:function(){
            $("#reMakeNum").val('');
            $("#confirmReceiveNum").val('');
        }

    }
});